import axios from 'axios'
import _ from 'lodash'
import { message } from 'antd'

const Post = (url, param) => {
  return new Promise((resolve, reject) => {
    let data = new FormData()
    _.each(param, (v, k) => {
      if (_.isNil(v)) v = ''
      data.append(k, v)
    })
    axios({
      method: 'POST',
      url: `/cattle${url}`,
      data
    })
      .then(response => {
        resolve(response.data.obj)
      })
      .catch(error => {
        message.error('请求错误')
        reject(error)
      })
  })
}

// 产品新增
export const productAddApi = param => {
  return Post('/product/add', param)
}

// 产品查询
export const productFindBypageApi = param => {
  return Post('/product/findBypage', param)
}

// 产品查询
export const productFindApi = param => {
  return Post('/product/find', param)
}

// 产品连接同步测试
export const productConnectSmbApi = param => {
  return Post('/product/connectSmb', param)
}

// 验证产品名唯一性
export const productCheckName = param => {
  return Post('/product/checkName', param)
}

// 产品修改
export const productUpdateApi = param => {
  return Post('/product/update', param)
}

// 产品删除
export const productDelApi = param => {
  return Post('/product/del', param)
}

// 用户连接同步测试
export const tuserConnectTcpApi = param => {
  return Post('/tuser/connectTcp', param)
}

// 用户新增
export const tuserAddApi = param => {
  return Post('/tuser/add', param)
}

// 用户查询
export const tuserFindBypageApi = param => {
  return Post('/tuser/findBypage', param)
}

// 查询用户联系方式
export const tuserGetPrincipal = () => {
  return Post('/tuser/getPrincipal')
}

// 验证用户名唯一性
export const tuserCheckName = param => {
  return Post('/tuser/checkName', param)
}

// 用户删除
export const tuserDelApi = param => {
  return Post('/tuser/del', param)
}

// 用户更新
export const tuserUpdateApi = param => {
  return Post('/tuser/update', param)
}

// 项目查询
export const projectFindBypageApi = param => {
  return Post('/project/findBypage', param)
}

// 项目新增
export const projectAddApi = param => {
  return Post('/project/add', param)
}

// 项目删除
export const projectDelApi = param => {
  return Post('/project/del', param)
}

// 项目更新
export const projectUpdateApi = param => {
  return Post('/project/update', param)
}

// 项目名称查重
export const projectCheckName = param => {
  return Post('/project/checkName', param)
}

// 任务新增
export const maintaskAddApi = param => {
  return Post('/maintask/add', param)
}

// 任务查询
export const maintaskFindBypageApi = param => {
  return Post('/maintask/findBypage', param)
}

// 首页任务看板查询
export const maintaskFindRealHiTaskApi = param => {
  return Post('/maintask/findRealHiTask', param)
}

// 单任务查询
export const maintaskFindApi = param => {
  return Post('/maintask/find', param)
}

//任务删除
export const maintaskDelApi = param => {
  return Post('/maintask/del', param)
}

//任务编辑
export const maintaskUpdateApi = param => {
  return Post('/maintask/update', param)
}

//历史列表查询
export const histaskFindBypageApi = param => {
  return Post('/histask/findBypage', param)
}

//历史文件查询
export const histaskFindFileByHisTaskIdApi = param => {
  return Post('/histask/findFileByHisTaskId', param)
}
//任务重启
export const resetTaskJobApi = param => {
  return Post('/maintask/resetTaskJob', param)
}

//任务暂停
export const stopTaskJobApi = param => {
  return Post('/maintask/stopTaskJob', param)
}

//任务统计列表
export const histaskFindTaskStaticInfoApi = param => {
  return Post('/histask/findTaskStaticInfo', param)
}

//任务概况
export const histaskFindTaskInfoApi = param => {
  return Post('/histask/findTaskInfo', param)
}

// 操作日志列表查询
export const operLogFindBypageApi = param => {
  return Post('/operLog/findBypage', param)
}
